#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>

void merge(int* nums1, int nums1Size, int m, int* nums2, int nums2Size, int n) {
    int tmp[6];
    if (m != 0 && n == 0)
    {
        return;
    }
    if (m == 0 && n != 0)
    {
        memcpy(nums1, nums2, sizeof(nums2[0]) * n);
        return;
    }
    int left1 = 0;
    int left2 = 0;
    int k = 0;
    while (left1 < m && left2 < n)
    {
        if (nums1[left1] > nums2[left2]) tmp[k++] = nums2[left2++];
        if (nums1[left1] <= nums2[left2]) tmp[k++] = nums1[left1++];
    }
    if (left1 == m && left2 != n)
    {
        while (left2 < n) tmp[k++] = nums2[left2++];
    }

    if (left1 != m && left2 == n)
    {
        while (left1 < m) tmp[k++] = nums1[left1++];
    }
    memcpy(nums1, tmp , sizeof(nums1[0])*nums1Size);
}

int main()
{
    int nums1[] = { 2,0 };
    int nums2[] = { 1 };
    merge(nums1, 2, 1, nums2, 1, 1);
    for (int i = 0; i < 2; i++)
    {
        printf("%d ",nums1[i]);
    }
    return 0;
}